package com.pulp.production.action;

import java.util.List;

import javax.servlet.ServletContext;
import javax.servlet.http.HttpServletRequest;

import org.apache.log4j.Logger;
import org.apache.struts2.ServletActionContext;
import org.springframework.web.context.WebApplicationContext;
import org.springframework.web.context.support.WebApplicationContextUtils;

import com.opensymphony.xwork2.ActionSupport;
import com.pulp.production.service.ProductionInfoService;

public class YieldRateAction<ProductionInfo> extends ActionSupport {

	private static final long serialVersionUID = 1L;
	private String REQUEST_RESULT = "ok";
	static Logger logger = Logger.getLogger(YieldRateAction.class);

	private String errorCode = "";

	private List yieldTotalYearList = null;
	private List yieldTotalMonthList = null;
	private List yieldTotalDateList = null;
	private List yieldPaperKindYear = null;
	private List yieldPaperKindMonth = null;
	private List yieldPaperKindDate = null;

	/**
	 * @return the rEQUEST_RESULT
	 */
	public String getREQUEST_RESULT() {
		return REQUEST_RESULT;
	}

	/**
	 * @param rEQUEST_RESULT the rEQUEST_RESULT to set
	 */
	public void setREQUEST_RESULT(String rEQUEST_RESULT) {
		REQUEST_RESULT = rEQUEST_RESULT;
	}

	/**
	 * @return the logger
	 */
	public static Logger getLogger() {
		return logger;
	}

	/**
	 * @param logger the logger to set
	 */
	public static void setLogger(Logger logger) {
		YieldRateAction.logger = logger;
	}

	/**
	 * @return the errorCode
	 */
	public String getErrorCode() {
		return errorCode;
	}

	/**
	 * @param errorCode the errorCode to set
	 */
	public void setErrorCode(String errorCode) {
		this.errorCode = errorCode;
	}

	/**
	 * @return the yieldTotalYearList
	 */
	public List getYieldTotalYearList() {
		return yieldTotalYearList;
	}

	/**
	 * @param yieldTotalYearList the yieldTotalYearList to set
	 */
	public void setYieldTotalYearList(List yieldTotalYearList) {
		this.yieldTotalYearList = yieldTotalYearList;
	}

	/**
	 * @return the yieldTotalMonthList
	 */
	public List getYieldTotalMonthList() {
		return yieldTotalMonthList;
	}

	/**
	 * @param yieldTotalMonthList the yieldTotalMonthList to set
	 */
	public void setYieldTotalMonthList(List yieldTotalMonthList) {
		this.yieldTotalMonthList = yieldTotalMonthList;
	}

	/**
	 * @return the yieldTotalDateList
	 */
	public List getYieldTotalDateList() {
		return yieldTotalDateList;
	}

	/**
	 * @param yieldTotalDateList the yieldTotalDateList to set
	 */
	public void setYieldTotalDateList(List yieldTotalDateList) {
		this.yieldTotalDateList = yieldTotalDateList;
	}

	/**
	 * @return the yieldPaperKindYear
	 */
	public List getYieldPaperKindYear() {
		return yieldPaperKindYear;
	}

	/**
	 * @param yieldPaperKindYear the yieldPaperKindYear to set
	 */
	public void setYieldPaperKindYear(List yieldPaperKindYear) {
		this.yieldPaperKindYear = yieldPaperKindYear;
	}

	/**
	 * @return the yieldPaperKindMonth
	 */
	public List getYieldPaperKindMonth() {
		return yieldPaperKindMonth;
	}

	/**
	 * @param yieldPaperKindMonth the yieldPaperKindMonth to set
	 */
	public void setYieldPaperKindMonth(List yieldPaperKindMonth) {
		this.yieldPaperKindMonth = yieldPaperKindMonth;
	}

	/**
	 * @return the yieldPaperKindDate
	 */
	public List getYieldPaperKindDate() {
		return yieldPaperKindDate;
	}

	/**
	 * @param yieldPaperKindDate the yieldPaperKindDate to set
	 */
	public void setYieldPaperKindDate(List yieldPaperKindDate) {
		this.yieldPaperKindDate = yieldPaperKindDate;
	}

	public String execute() throws Exception {

		try {

			HttpServletRequest request = (HttpServletRequest) ServletActionContext.getRequest();

			ServletContext servletContext = ServletActionContext.getServletContext();
			WebApplicationContext wac = WebApplicationContextUtils.getWebApplicationContext(servletContext);
			ProductionInfoService productionInfoService = (ProductionInfoService) wac.getBean("productionInfoService");
			yieldTotalYearList = productionInfoService.getYieldTotalYear();
			yieldTotalMonthList = productionInfoService.getYieldTotalMonth();
			yieldTotalDateList = productionInfoService.getYieldTotalDate();
			yieldPaperKindYear = productionInfoService.getYieldPaperKindYear();
			yieldPaperKindMonth = productionInfoService.getYieldPaperKindMonth();
			yieldPaperKindDate = productionInfoService.getYieldPaperKindDate();

			request.setAttribute("yieldTotalYearList", yieldTotalYearList);
			request.setAttribute("yieldTotalMonthList", yieldTotalMonthList);
			request.setAttribute("yieldTotalDateList", yieldTotalDateList);
			request.setAttribute("yieldPaperKindYear", yieldPaperKindYear);
			request.setAttribute("yieldPaperKindMonth", yieldPaperKindMonth);
			request.setAttribute("yieldPaperKindDate", yieldPaperKindDate);
		} catch (Exception ex) {
			REQUEST_RESULT = "FAILED";
			ex.printStackTrace();
		}
		return REQUEST_RESULT;
	}

}
